var ksfrom = {

    /**
     * 清空form 目前只可清空文本
     * @param form
     * created by dale 2017/6/27 下午5:17
     */
   clearFromData: function clearForm(form) {
    // input清空
        $(':input', form).each(function () {
            var type = this.type;
            var tag = this.tagName.toLowerCase(); // normalize case
            if (type == 'text' || type == 'password' || tag == 'textarea')
                this.value = "";
            // 多选checkboxes清空
            // select 下拉框清空
            else if (tag == 'select')
                this.selectedIndex = -1;
        });
    }
};

var timeLine = {
    /**
     * 创建时间轴
     * @param wraper 容器
     * @param _content 内容
     * created by dale 2017/6/27 下午5:11
     * 
     */
    create:function create(wraper,_content) {

        var _default = {
            title:'跟进情况',
            showTotal:true,
            showEdit:true,
            showYear:true,
            showDelete:false,
            items:[
                {id:'13',title: 'title', content:'content',images:'',files:'',imgPath:'',filePath:'', footer:{left:'footer',right:'111'},time:'2017-6-27'},
                {id:'14',title: 'title', content:'content',images:'',files:'',imgPath:'',filePath:'', footer:{left:'footer',right:'111'},time:'2017-6-27'}
            ]
        };

        var _content=$.extend({}, _default, _content);
        $('#title').empty();
        $('#title').append(_content.title);
        timeLine.isShowTotal(_content.showTotal,_content.items);//显示记录数

        var contentStr='';
        
        for(var i=0;i<_content.items.length;i++){
            if(i==_content.items.length-1&&_content.title=='跟进情况'){
               contentStr= timeLine.isShowFirst(contentStr,_content.items[i],_content.showDelete,_content.showEdit);
                break;
            }
            contentStr+=timeLine.isShowYear(_content.showYear,_content.items,i);
            contentStr+='<div id="'+_content.items[i].id+'" class="timeline-row alt">' ;
            contentStr+= ' <div class="timeline-item"> ' ;
            if(_content.items[i].bFinish){
                contentStr+= ' <div class="timeline-icon recycleGreen"> ' ;
            }else {
                contentStr+=    '<div class="timeline-icon " >' ;
            }

            contentStr+= '<small style="font-size: xx-small" >'+_content.items[i].time.split('-')[1]+'-'+_content.items[i].time.split('-')[2].split(' ')[0]+' </small>' +
                ' </div>'+
                '<div class="timeline-item-inner">' +
                ' <div class="timeline-body"> ' +
                '<div class="timeline-content" style="margin-left: 0px" > ' +
                '<div class="font-12" style="margin-bottom: 10px;"><font>'+_content.items[i].title+'</font> ' ;


            contentStr+=timeLine.isShowDelete(_content.showDelete,_content.items[i].id);
            contentStr+=timeLine.isShowEdit(_content.showDelete,_content.showEdit,_content.items[i].id);
            if(typeof(_content.items[i].showCheck) != "undefined"){
                contentStr+=timeLine.isShowCheck(_content.items[i].showCheck,_content.items[i].id);
            }
            contentStr+='</div> ' ;

            if(_content.items[i].retain!=''&&_content.items[i].retain!=undefined){
                contentStr+= '<div class="font-12" style="margin-bottom: 10px;"><font>'+_content.items[i].retain+'</font> </div> '
            }

            contentStr+='<div class=" font-16" style="margin-bottom: 10px"><p>'+_content.items[i].content+'</p> </div> '
            if (_content.items[i].images!=null){
                contentStr+=timeLine.showImage(_content.items[i].images,_content.items[i].id,_content.items[i].imgPath,_content.showDelete);
            }else {
                contentStr+='';
            }
            if (_content.items[i].files!=null){
                contentStr+=timeLine.showFile(_content.items[i].files,_content.items[i].id,_content.items[i].filePath);
            }else {
                contentStr+='';
            }

            contentStr+= '<div class="text-muted" ><small class=" text-muted m-bottom-xs pull-left">'+_content.items[i].footer.left+'</small> <small class=" text-muted m-bottom-xs pull-right">'+_content.items[i].footer.right+'</small></div>' +
                '</div>' +
                '</div>' +
                ' </div>' +
                ' </div>'+
                 '</div>';
        }

        wraper.empty();
        wraper.append(contentStr);
    },
    /**
     * 图片处理
     * @param images
     * @returns {*}
     * created by dale 2017/6/29 下午2:00
     */
    showImage:function (images,id,path,showDelete) {
        if(images!=''){
            var content='<div  id="imageList_'+id+'" style="margin-bottom: 10px;"><ul class="uploaded-photo-list m-top-sm clearfix images" >'
            var array=images.split(',');
            for(var i=0;i<array.length-1;i++){
                var url=path+array[i];
                content+=' <li><table><tbody><tr><td><img src='+url+' alt="Picture'+(i+1)+'"  height="100px"></td></tr>' ;
                if(showDelete){
                    content+=  '<tr><td><a  id="imageDelete_'+id+'_'+i+'" style="text-align: center;margin-bottom: 10px; cursor:pointer;" class="my-btn">删除</a></td></tr>';
                }
                content+='</tbody></table></li>';
            }
            content+=  '</ul></div>';
            return content;
        }else {
            return '';
        }

    },

    showFile:function (files,id,path) {
        if(files!=''){
            var content='<div  id="fileList_'+id+'" style="margin-bottom: 10px;"><ul class=" m-top-sm clearfix " style="list-style: none">'
            var array=files.split(',');
            for(var i=0;i<array.length-1;i++){
               var kkk= array[i].split('/');
                var name=kkk[kkk.length-1];
                var url=path+array[i];
                var footer=name.split('.')[1];
                if(footer=='pdf'){
                    var icon='<i class="fa fa-file-pdf-o fa-2x"   aria-hidden="true"></i>';
                }else if(footer=='xlsx'){
                    var icon='<i class="fa fa-file-excel-o fa-2x"   aria-hidden="true"></i>';
                }else if(footer=='docx'){
                    var icon='<i class="fa fa-file-word-o fa-2x"   aria-hidden="true"></i>';
                }else {
                    var icon='<i class="fa fa-file-o fa-2x"   aria-hidden="true"></i>';
                }
                
                

                content+=' <li style="float: left;margin-right:5px; "><div title="'+name+'"><a target="_blank" href="'+url+'" style="text-align: center;width: 30px;margin-bottom: 10px;" >' ;
                content+= icon;
                content+= '</a></div></li>';
            }
            content+=  '</ul></div>';
            return content;
        }else {
            return '';
        }
    },
    
    /**
     * 是否显示记录数
     * @param showTotal 是否显示记录数
     * @param items 数组
     * created by dale 2017/6/27 下午5:12
     */

    isShowTotal:function (showTotal,items) {
        if(showTotal){
            $('#total').empty();
            $('#total').append('总共'+items.length+'记录');
        }else {
            $('#total').empty();
        }
    },
    /**
     * 显示年份
     * @param showYear 是否显示
     * @param items    数组
     * @param i        位置
     * @returns {*}    返回网页文本
     * created by dale 2017/6/27 下午5:12
     */
    isShowYear:function (showYear,items,i) {
        if(showYear&&timeLine.compareYear(items,i)!='0'){
            var yearStr='<div class="timeline-year "> <font>'+items[i].time.split('-')[0]+'</font> </div>';
            return yearStr;
        }else {
            return '';
        }
    },
    /**
     * 比较年份
     * @param items 数组
     * @param i     序号
     * @returns {*} 返回标记
     * created by dale 2017/6/27 下午5:14
     */
    compareYear:function (items,i) {
        if(i==0){
            return '1';
        }else{
            if(items[i].time.split('-')[0]==items[i-1].time.split('-')[0]){
                return '0'
            }else {
                return '1';
            }
        }
    },
    /**
     * 是否显示编辑
     * @param showDelete 是否删除
     * @param showEdit   是否编辑
     * @param id         标号 主键唯一
     * @returns {*}      返回网页文本
     * created by dale 2017/6/27 下午5:15
     * modified by dale 2017/6/27 下午8:38
     */
    isShowEdit:function (showDelete,showEdit,id) {
        if(showEdit){
            if(showDelete){
                var editStr='<a id="edit_'+ id +'" data-toggle="modal" data-target="#model"  class="btn  btn-xs my-btn pull-right" style="margin-right: 10px;" >编辑</a>';
                return editStr;
            }else {
                var editStr='<a id="edit_'+ id +'" data-toggle="modal" data-target="#model"  class="btn  btn-xs my-btn pull-right"  >编辑</a>';
                return editStr; 
            }
            
        }else {
            return '';
        }
    },

    isShowCheck : function (showCheck,id) {
        if (showCheck){
            return '<a id="check_'+ id +'" data-toggle="modal" data-target="#model"  class="btn  btn-xs my-btn pull-right" style="margin-right: 10px;" >审核</a>';
        }else {
            return '';
        }
    },

    /**
     * 是否显示删除
     * @param showDelete
     * @param id
     * @returns {*}
     *
     * created by dale 2017/6/27 下午7:47
     */
    isShowDelete:function(showDelete,id){
        if(showDelete){
            var deleteStr='<a id="delete_'+ id +'" class="btn   btn-xs my-btn pull-right" >删除</a>';
            return deleteStr;
        }else {
            return '';
        }
    },
    /**
     * 第一条显示上部
     * @param content
     *created by dale 2017/7/10 下午12:02
     * 
     */

    isShowFirst:function (content,item,showDelete,showEdit) {
        var contentStr='';
        contentStr+='<div id="'+item.id+'" class="timeline-row alt">' ;
        contentStr+= ' <div class="timeline-item"> ' +
            '<div class="timeline-icon " >' +
            '<small style="font-size: xx-small" > 首 </small>' +
            ' </div>'+
            '<div class="timeline-item-inner">' +
            ' <div class="timeline-body"> ' +
            '<div class="timeline-content" style="margin-left: 0px" > ' +
            '<div class="font-12 " style="margin-bottom: 10px;"><font >'+item.title+'</font> ' ;


        contentStr+=timeLine.isShowDelete(showDelete,item.id);
        contentStr+=timeLine.isShowEdit(showDelete,showEdit,item.id);
        contentStr+='</div> <div class=" font-16 " style="margin-bottom: 10px"><p>'+item.content+'</p> </div> '
        if (item.images!=null){
            contentStr+=timeLine.showImage(item.images,item.id,item.imgPath,showDelete);
        }else {
            contentStr+='';
        }
        if (item.files!=null){
            contentStr+=timeLine.showFile(item.files,item.id,item.filePath);
        }else {
            contentStr+='';
        }

        contentStr+= '<div class="text-muted" ><small class=" text-muted m-bottom-xs pull-left">'+item.footer.left+'</small> <small class=" text-muted m-bottom-xs pull-right">'+item.footer.right+'</small></div>' +
            '</div>' +
            '</div>' +
            ' </div>' +
            ' </div>'+
            '</div>';
        return contentStr+=content;
    },

    /**
     * 编辑
     * @param wraper 容器
     * @param _content 内容
     *
     * created by dale 2017/6/27 下午5:16
     * modified by dale 2017/6/27 下午8:54 修复因单个刷新,引起的删除键消失的问题
     */
    edit:function (wraper,_content) {
        //设定默认配置并合并新配置
        var _default = {
            showEdit:true,
            showDelete:false,
            item: {id:'13',title: 'title', content:'content',imgPath:'',filePath:'', footer:{left:'footer',right:'111'},date:'6-27',time:'2017-6-27'},

        };
        var _content=$.extend({}, _default, _content);

        // timeLine.isShowTotal(_content.showTotal,_content.items);//显示记录数

        var contentStr='';
        contentStr+= ' <div class="timeline-item"> ' +
            '<div class="timeline-icon " >' +
            '<small style="font-size: xx-small" >'+_content.item.time.split('-')[1]+'-'+_content.item.time.split('-')[2].split(' ')[0]+' </small>' +
            ' </div>'+
            '<div class="timeline-item-inner">' +
            ' <div class="timeline-body"> ' +
            '<div class="timeline-content" style="margin-left: 0px" > ' +
            '<div class="font-12 " style="margin-bottom: 10px;"><font>'+_content.item.title+'</font> ' ;

        contentStr+=timeLine.isShowDelete(_content.showDelete,_content.item.id);
        contentStr+=timeLine.isShowEdit(_content.showDelete,_content.showEdit,_content.item.id);
        if(typeof(_content.item.showCheck) != "undefined"){
            contentStr+=timeLine.isShowCheck(_content.item.showCheck,_content.item.id);
        }
        contentStr+='</div> ';
        if(_content.item.retain!=''&&_content.item.retain!=undefined){
            contentStr+= '<div class="font-12" style="margin-bottom: 10px;"><font>'+_content.item.retain+'</font> </div> '
        }
        contentStr+= '<div class=" font-16 " style="margin-bottom: 10px"><p>'+_content.item.content+'</p> </div> ';
            if (_content.item.images!=null){
                contentStr+=timeLine.showImage(_content.item.images,_content.item.id,_content.item.imgPath,_content.showDelete);
            }else {
                contentStr+='';
            }
            if (_content.item.files!=null){
                contentStr+=timeLine.showFile(_content.item.files,_content.item.id,_content.item.filePath);
            }else {
                contentStr+='';
            }
        contentStr+='<div class="text-muted" ><small class=" text-muted m-bottom-xs pull-left">'+_content.item.footer.left+'</small> <small class=" text-muted m-bottom-xs pull-right">'+_content.item.footer.right+'</small></div>' +
            '</div>' +
            '</div>' +
            ' </div>' +
            ' </div>'

        wraper.empty();
        wraper.append(contentStr);
        
    },
    /**
     * 加载有删除的时间轴
     * @param wraper 容器
     * @param data   json 
     * @param title  类型标题
     * created by dale 2017/6/27 下午8:47
     * modified by dale 2017/6/28 上午9:11 自动进行内容判断,如果是数组,则全局刷新,如果是单个数据则刷新局部
     */
    loadTimeLine:function (wraper,data,title,showDelete,showEdit) {
        if(data instanceof Array){
            content = {
                title:title,
                showTotal:true,
                showEdit:showEdit,
                showDelete:showDelete,
                showYear:true,
                items:data,
            };
            timeLine.create(wraper,content);
        }else {
            var $div=$('#'+data.id);
            content = {
                showEdit:showEdit,
                showDelete:showDelete,
                item:data,
            };
            timeLine.edit($div,content);
        }
        
    },
    /**
     * 加载没有删除的时间轴
     * @param wraper 容器
     * @param data   时间
     * @param title  标题
     * created by dale 2017/6/27 下午8:49
     * modified by dale 2017/6/28 上午9:12 自动进行内容判断,如果是数组,则全局刷新,如果是单个数据则刷新局部
     */

    loadWithoutDelete:function (wraper,data,title) {
        if(data instanceof Array){
            content = {
                title:title,
                showTotal:true,
                showEdit:true,
                showDelete:false,
                showYear:true,
                items:data,
            };
            timeLine.create(wraper,content);
        }else {
            var $div=$('#'+data.id);
            content = {
                showEdit:true,
                showDelete:false,
                item:data,
            };
            timeLine.edit($div,content);
        }
        
    },
}

var fileInput = {
    /**
     *
     * @param ctrlName
     * @param uploadUrl
     * created by dale 2017/6/28 下午5:23
     */
    initFileInput:function (ctrlName, uploadUrl) {
        var control = $('#' + ctrlName);
        control.fileinput({
            language: 'zh', //设置语言
            uploadUrl: uploadUrl, //上传的地址
            allowedFileExtensions : ['jpg', 'png','gif','xlsx','docx','pdf','xls'],//接收的文件后缀
            uploadAsync: true, //默认异步上传
            showUpload: true, //是否显示上传按钮
            showCaption: false,//是否显示标题
            dropZoneEnabled: false,
            browseClass: "btn btn-primary", //按钮样式
            maxFileSize: 6000,
            maxFileCount: 10, //表示允许同时上传的最大文件个数
            enctype: 'multipart/form-data',
            validateInitialCount:true,
            height:200,
            previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
            msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！"
        });
    }
};

$.fn.extend({
    /**
     * 验证
     * @param _selector
     * created by dale 2017/7/11 下午4:14
     */
    initeValidate:function (_selector) {
        var mustDom = this.find('[must=true]');
        var check;
        mustDom.each(function () {
            $(this).attr('placeholder','必填');
            $(this).parent().addClass('has-warning');

           if($(this).val() != '') $(this).parent().removeClass('has-warning').addClass('has-success');
            
        });
        //this.find('[name$="tTrackTime"]').parent().removeClass('has-warning').addClass('has-success');
        mustDom.on('change keyup', function(){
            if($(this).val() != '') $(this).parent().removeClass('has-warning').addClass('has-success');
            else $(this).parent().removeClass('has-success').addClass('has-warning');
            if(_selector){
                check = true;
                mustDom.each(function(){
                    if($(this).val() == '') check = false;
                });
                if(check) _selector.removeClass('disabled');
                else _selector.addClass('disabled');
            }
        });
    },
    initeVlidateWithSelect:function (_selector) {
        var mustDom = this.find('[must=true]');
        var check;
        var selectCheck;
        mustDom.each(function () {
            $(this).attr('placeholder','必填');
            $(this).parent().addClass('has-warning');
            if($(this).val() != '') $(this).parent().removeClass('has-warning').addClass('has-success');
        });
        this.find('[name$="tTrackTime"]').parent().removeClass('has-warning').addClass('has-success');
        mustDom.on('change keyup', function(){
            if($(this).val() != '') $(this).parent().removeClass('has-warning').addClass('has-success');
            else $(this).parent().removeClass('has-success').addClass('has-warning');
            if(_selector){
                var check=true;
                var selectCheck=true;
                mustDom.each(function(){
                    if($(this).val() == '') check = false;
                });
                $('select').each(function(){
                    if($(this).val() == ''||$(this).val() == '-1') selectCheck = false;
                });
                if(check&&selectCheck) _selector.removeClass('disabled');
                else _selector.addClass('disabled');
            }
        });
        $('select').each(function () {
            $(this).parent().addClass('has-warning');
        });
        $('select').on('change', function(){
            if($(this).val() != ''&&$(this).val() != '-1') $(this).parent().removeClass('has-warning').addClass('has-success');
            else $(this).parent().removeClass('has-success').addClass('has-warning');
            if(_selector){
                var check=true;
                var selectCheck=true;
                $('select').each(function(){
                    if($(this).val() == ''||$(this).val() == '-1') selectCheck = false;
                });
                mustDom.each(function(){
                    if($(this).val() == '') check = false;
                });
                if(selectCheck&&check) _selector.removeClass('disabled');
                else _selector.addClass('disabled');
            }
        });

    }
});


var myEnum = {

    /**
     * 初始化枚举一个
     * @param _selector 选择器
     * @param url       地址
     * @param QueryName 传递的参数
     * created by dale 2017/7/11 下午4:18
     */
    inintEnum:function (_selector,url,queryName) {
        $.ajax({ 
            url : url,
            data:{name:queryName},
            dataType:'json',
            type:'post',
            success:function (data) {
                // console.log(data);
                _selector.empty();
                _selector.append('<option value="" selected style="display: none">请选择</option>')
                $.each(data,function (val,text) {
                    _selector.append('<option value="'+val+'">'+text+'</option>');
                })
            },
            error:function (result) {
                console.log(result);
            }
        });
    },
    /**
     * 根据json串初始化枚举
     * @param _option
     * 
     * created by dale 2017/7/11 下午4:30
     */
    inintEnums:function (_option) {
        var _default={
            items:[
                {selector:'', url:'', queryName:''},
            ]
        };
        for(var i=0;i<_option.items.length;i++){
            this.inintEnum(_option.items[i].selector,_option.items[i].url,_option.items[i].queryName);
        }
    },

    
};

var myWindow={
    /**
     * 顶层窗口弹出,sweetalert2
     * @param _options
     * @param actFunc
     * @param disFunc
     *created by dale 2017/7/11 下午5:12
     */
    initPopUp:function (_options,actFunc,disFunc) {
        var _default={
            title: '确认删除',
            text: '你确定要删除这条记录吗?',
            type: 'warning',
            showCancelButton: true,
            confirmButtonText: '确定',
            cancelButtonText: '取消',
        }
        if(!disFunc){
            disFunc=function (dismiss) {
                if(dismiss=='cancel'){
                    return false;
                }
            }
        }
        var _options=$.extend({}, _default, _options);
        window.top.swal(_options).then(actFunc,disFunc);
    }
    
};

var myArea={
    /**
     * 
     * @param _options
     */
    loadArea:function (_options) {
        var _default={
            selectors:[],   //控制器数组
            pid:0,          //父id    合并默认即可
            level:1,        //城市等级  合并默认即可
            i:0,             //控制器位置 合并默认即可
            url:baseUrl+"customer/getAreaData"
        }
        var _options=$.extend({}, _default, _options);
        myArea.initArea(_options.selectors,_options.pid,_options.level,_options.i,_options.url);
    },
     /**
      * 初始化省县市
      * @param selectors 选择器名字数组
      * @param pid       父id
      * @param level     城市等级
      * @param i         控制器位置
      * @param url        地址
      */
    // initArea:function (selectors,pid,level,i,url) {
    //         $('#'+selectors[i]).select2({
    //             placeholder:'请选择',
    //             ajax: {
    //                 url:url,
    //                 dataType: 'json',
    //                 type:'POST',
    //                 delay: 250,
    //                 data: function (params) {
    //                     return {
    //                         qname: params.term,
    //                         id:pid,
    //                         level:level
    //                     };
    //                 },
    //                 processResults: function (data, params) {
    //                     return {
    //                         results: data,
    //                     };
    //                 },
    //                 cache: true,
    //             },
    //             escapeMarkup: function (markup) {
    //                 $('#select2-'+selectors[i]+'-container').parent().addClass('warn-color');
    //
    //                 return markup; }, // let our custom formatter work
    //             templateResult: function formatRepo(repo){
    //                 return repo.text}, // omitted for brevity, see the source of this page
    //             templateSelection: function formatRepoSelection(repo){
    //                 if(repo.id!=""){
    //                     $('#select2-'+selectors[i]+'-container').parent().removeClass('warn-color').addClass('success-color');
    //                     for(var j=i+1;j<3;j++){
    //                         $('#'+selectors[j]).val(null).trigger("change");
    //                     }
    //                 }
    //
    //                 if(i<2){
    //                     myArea.initArea(selectors,repo.id,level+1,i+1,url);
    //                 }
    //                 return repo.text
    //             } // omitted for brevity, see the source of this page
    //         });
    // }
     




    initArea:function (selectors,pid,level,i,url) {
        $('#'+selectors[i]).select2({
            placeholder:'请选择',
            ajax: {
                url:url,
                dataType: 'json',
                type:'POST',
                delay: 250,
                data: {id:pid},
                processResults: function (data, params) {
                    return {
                        results: data,
                    };
                },
                cache: true,
            },
            escapeMarkup: function (markup) {
                $('#select2-'+selectors[i]+'-container').parent().addClass('warn-color');

                return markup; }, // let our custom formatter work
            templateResult: function formatRepo(repo){
                return repo.text}, // omitted for brevity, see the source of this page
            templateSelection: function formatRepoSelection(repo){
                if(repo.id!=""){
                    $('#select2-'+selectors[i]+'-container').parent().removeClass('warn-color').addClass('success-color');
                    for(var j=i+1;j<3;j++){
                        $('#'+selectors[j]).val(null).trigger("change");
                    }
                }

                if(i<2){
                    myArea.initArea(selectors,repo.id,level+1,i+1,url);
                }
                return repo.text
            } // omitted for brevity, see the source of this page
        });
    }

} ;


var addressUri={
    /**
     * 获取网页后面的参数
     * @param name
     * @returns {null}
     */
    getParam: function (name) {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        }
        return null;
    }
};
var modalBind={
    bindClick:function () {
        window.top.xhTop.getModalCloseDom().click(function () {
            var saveBtn = window.top.xhTop.getModalConfirmDom();
            if(saveBtn.hasClass('disabled') || saveBtn.is(":hidden") ){
                modalBind.disabledClick();
            }else {
                modalBind.enableClick();
            }
            return false;
        });

    },
    disabledClick:function () {
        window.top.xhTop.closeModal();
        return false;
    },
    enableClick:function () {
        window.top.swal({
            title: '你确定要关闭吗?',
            text: '',
            type: 'warning',
            showCancelButton: true,
            confirmButtonText: '保存并关闭',
            cancelButtonText: '关闭'
        }).then(function() {

            window.top.xhTop.getModalConfirmDom().click();
            window.top.xhTop.closeModal();
        }, function(dismiss) {
            // dismiss can be 'overlay', 'cancel', 'close', 'esc', 'timer'
            if (dismiss === 'cancel') {
                window.top.xhTop.closeModal();
            }
        })

        return false;
    }
}

/**
 * Date扩展
 * @param format
 * @returns {*}
 */
Date.prototype.format =function(format)
{
    var o = {
        "M+" : this.getMonth()+1, //month
        "d+" : this.getDate(), //day
        "h+" : this.getHours(), //hour
        "m+" : this.getMinutes(), //minute
        "s+" : this.getSeconds(), //second
        "q+" : Math.floor((this.getMonth()+3)/3), //quarter
        "S" : this.getMilliseconds() //millisecond
    }
    if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
        (this.getFullYear()+"").substr(4- RegExp.$1.length));
    for(var k in o)if(new RegExp("("+ k +")").test(format))
        format = format.replace(RegExp.$1,
            RegExp.$1.length==1? o[k] :
                ("00"+ o[k]).substr((""+ o[k]).length));
    return format;
}
